//
//  DLayout.m
//  ERenYiPu
//
//  Created by Erep on 16/5/13.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "DLayout.h"
#import "sys/utsname.h"
#import  <AdSupport/AdSupport.h>

#import "sys/utsname.h"
#import <AdSupport/AdSupport.h>


#define IOS_CELLULAR    @"pdp_ip0"
#define IOS_WIFI        @"en0"
//#define IOS_VPN       @"utun0"
#define IP_ADDR_IPv4    @"ipv4"
#define IP_ADDR_IPv6    @"ipv6"

// 4s
#define Width4s 640
#define Height4s 960


// 5
#define Width5s 640
#define Height5s 1136

// 6
#define Width6 750
#define Height6 1334

// 6sp
#define Width6sp 1080
#define Height6sp 1920

// x
#define WidthX 1125
#define HeightX 2436

@implementation DLayout
+ (instancetype)sharedInstance {

    static DLayout *instance = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        instance = [[DLayout alloc] init];
    });
    return instance;
}

/**
 *  手机型号
 *
 *  @return e.g. iPhone     */
+ (NSString *)phoneModel {
    
    return [[UIDevice currentDevice] model];
}

/**
 *  手机系统版本
 *
 *  @return e.g. 8.0
 */
+ (NSString *)phoneVersion{
 
    return [NSString stringWithFormat:@"%@ %@",[[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion]];
}

/**
 *  UUID
 *
 */
+ (NSString *)identifier
{
    NSUUID *uuid = [[UIDevice currentDevice] identifierForVendor];
    
    return  uuid.UUIDString;
}

+ (NSString*) uuid {

    CFUUIDRef puuid = CFUUIDCreate( nil );
    CFStringRef uuidString = CFUUIDCreateString( nil, puuid );
    NSString * result = (NSString *)CFBridgingRelease(CFStringCreateCopy( NULL, uuidString));
    CFRelease(puuid);
    CFRelease(uuidString);
    return result;
    
}

/**
 *  设备别名
 *
 */
+ (NSString *)phoneName
{
    return [[UIDevice currentDevice] name];
}
/**
 *  获取当前设备的分辨率
 *
 *  @return 获取当前设备的分辨率宽
 */
+ (CGFloat)getWidth {
    
    NSString *str = [self deviceVersion];
    
    NSLog(@"%@",str);

    if ([str isEqualToString:@"iPhone 4"])            return Width4s;
    if ([str isEqualToString:@"Verizon iPhone 4"])    return Width4s;
    if ([str isEqualToString:@"iPhone 4S"])    return Width4s;
    if ([str isEqualToString:@"iPhone 5"])     return Width5s;
    if ([str isEqualToString:@"iPhone 5"])     return Width5s;
    if ([str isEqualToString:@"iPhone 5C"])    return Width5s;
    if ([str isEqualToString:@"iPhone 5C"])    return Width5s;
    if ([str isEqualToString:@"iPhone 5S"])    return Width5s;
    if ([str isEqualToString:@"iPhone 5S"])    return Width5s;
    if ([str isEqualToString:@"iPhone 6 Plus"])    return Width6sp;
    if ([str isEqualToString:@"iPhone 6"])         return Width6;
    if ([str isEqualToString:@"iPhone 6s"])        return Width6;
    if ([str isEqualToString:@"iPhone 6s Plus"])   return Width6sp;
    
    if ([str isEqualToString:@"iPhone X"]) { return WidthX;
        
    }
    
    return Width6;
}

/**
 *  获取当前设备的分辨率
 *
 *  @return 获取当前设备的分辨率高
 */
+ (CGFloat)getHeigth {
    
    NSString *str = [self deviceVersion];
    
    //iPhone
//    if ([str isEqualToString:@"iPhone 1G"])     return @"iPhone 1G";
//    if ([str isEqualToString:@"iPhone 3G"])     return @"iPhone 3G";
//    if ([str isEqualToString:@"iPhone 3GS"])    return @"iPhone 3GS";
    if ([str isEqualToString:@"iPhone 4"])      return Height4s;
    if ([str isEqualToString:@"Verizon iPhone 4"])    return Height4s;
    if ([str isEqualToString:@"iPhone 4S"])    return Height4s;
    if ([str isEqualToString:@"iPhone 5"])    return Height5s;
    if ([str isEqualToString:@"iPhone 5"])    return Height5s;
    if ([str isEqualToString:@"iPhone 5C"])    return Height5s;
    if ([str isEqualToString:@"iPhone 5C"])    return Height5s;
    if ([str isEqualToString:@"iPhone 5S"])    return Height5s;
    if ([str isEqualToString:@"iPhone 5S"])    return Height5s;
    if ([str isEqualToString:@"iPhone 6 Plus"])    return Height6sp;
    if ([str isEqualToString:@"iPhone 6"])    return Height6;
    if ([str isEqualToString:@"iPhone 6s"])    return Height6;
    if ([str isEqualToString:@"iPhone 6s Plus"])    return Height6sp;
    
    if ([str isEqualToString:@"iPhone X"]) { return HeightX;
        
    }
    
    return Height6;
}

/**
 *  设备版本
 *
 *  @return e.g. iPhone 5S
 */
+ (NSString*)deviceVersion
{
    // 需要#import "sys/utsname.h"
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
    //iPhone
    if ([deviceString isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
    if ([deviceString isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
    if ([deviceString isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
    if ([deviceString isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
    if ([deviceString isEqualToString:@"iPhone3,2"])    return @"Verizon iPhone 4";
    if ([deviceString isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
    if ([deviceString isEqualToString:@"iPhone5,1"])    return @"iPhone 5";
    if ([deviceString isEqualToString:@"iPhone5,2"])    return @"iPhone 5";
    if ([deviceString isEqualToString:@"iPhone5,3"])    return @"iPhone 5C";
    if ([deviceString isEqualToString:@"iPhone5,4"])    return @"iPhone 5C";
    if ([deviceString isEqualToString:@"iPhone6,1"])    return @"iPhone 5S";
    if ([deviceString isEqualToString:@"iPhone6,2"])    return @"iPhone 5S";
    if ([deviceString isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
    if ([deviceString isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
    if ([deviceString isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
    if ([deviceString isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
    
    //iPod
    
    if ([deviceString isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
    if ([deviceString isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
    if ([deviceString isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
    if ([deviceString isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
    if ([deviceString isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G"; 
    
    //iPad
    if ([deviceString isEqualToString:@"iPad1,1"])      return @"iPad";
    if ([deviceString isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
    if ([deviceString isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
    if ([deviceString isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
    if ([deviceString isEqualToString:@"iPad2,4"])      return @"iPad 2 (32nm)";
    if ([deviceString isEqualToString:@"iPad2,5"])      return @"iPad mini (WiFi)";
    if ([deviceString isEqualToString:@"iPad2,6"])      return @"iPad mini (GSM)";
    if ([deviceString isEqualToString:@"iPad2,7"])      return @"iPad mini (CDMA)";
    
    if ([deviceString isEqualToString:@"iPad3,1"])      return @"iPad 3(WiFi)";
    if ([deviceString isEqualToString:@"iPad3,2"])      return @"iPad 3(CDMA)";
    if ([deviceString isEqualToString:@"iPad3,3"])      return @"iPad 3(4G)";
    if ([deviceString isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
    if ([deviceString isEqualToString:@"iPad3,5"])      return @"iPad 4 (4G)";
    if ([deviceString isEqualToString:@"iPad3,6"])      return @"iPad 4 (CDMA)";
    
    if ([deviceString isEqualToString:@"iPad4,1"])      return @"iPad Air";
    if ([deviceString isEqualToString:@"iPad4,2"])      return @"iPad Air";
    if ([deviceString isEqualToString:@"iPad4,3"])      return @"iPad Air";
    if ([deviceString isEqualToString:@"iPad5,3"])      return @"iPad Air 2";
    if ([deviceString isEqualToString:@"iPad5,4"])      return @"iPad Air 2";
    if ([deviceString isEqualToString:@"i386"])         return @"Simulator";
    if ([deviceString isEqualToString:@"x86_64"])       return @"Simulator";
    
    if ([deviceString isEqualToString:@"iPad4,4"]||[deviceString isEqualToString:@"iPad4,5"]||[deviceString isEqualToString:@"iPad4,6"]) return @"iPad mini 2";
    
    if ([deviceString isEqualToString:@"iPad4,7"]||[deviceString isEqualToString:@"iPad4,8"]||[deviceString isEqualToString:@"iPad4,9"]) return @"iPad mini 3";
    
    return deviceString;
}

+ (NSString *)uniqueDeviceAdvertisingIdentifier {
    
    NSString *uniqueIdentifier = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    return uniqueIdentifier;
}


@end
